/*
Copyright 2010,2011 Matt Van Der Westhuizen

This file is part of Jumpers.

Jumpers is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Jumpers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Jumpers.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.chaoticengine.cgll.entity.component.cleanup;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.state.StateBasedGame;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

/**
 * Component that expires its parent entity after a fixed period of time.
 *
 * @author Matt v.d. Westhuizen
 */
@Root
public class TimedExpireComponent extends ExpireComponent {
    protected int delayMs = 0;
    protected int passedMs = 0;

    /**
     * Constructor.
     *
     * @param delayMs The number of milliseconds to wait before destroying the
     * owning entity.
     */
    public TimedExpireComponent() {
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sb, int delta) {
        passedMs += delta;

        if (passedMs >= delayMs) {
            owner.destroy();
        }
    }

    @Element(name="duration")
    public int getDuration() {
        return(delayMs);
    }

    @Element(name="duration")
    public void setDuration(int delayMs) {
        this.delayMs = delayMs;
    }
}
